package main;

import java.awt.Graphics;
import java.awt.image.BufferedImage;
import physics.Position;
import physics.RK4;

/**
 * 
 * @author Dylan
 *
 * 2D object with both linear and angular vectors.
 */

public class Obj extends Sprite{
	
	public Position xVector, yVector, RotVector;
	public double xAcceleration, yAcceleration, RotAcceleration;
	public double mass = 1;
	
	public Obj(BufferedImage image, int layer, double x, double y) {
		super(image, layer);
		
		xVector = new Position(x, 0);
		yVector = new Position(y, 0);
		RotVector = new Position(0, 0);
		xAcceleration = yAcceleration = RotAcceleration = 0;
	}
	
	public void draw(Graphics g){
		x = xVector.pos;
		y = yVector.pos;
		rot = RotVector.pos;
		super.draw(g);
	}
	
	public void move(RK4 integrator, double t, double dt){
		yVector.a += 10;	//gravity
		
		//air friction
		xVector.a -= .1*xVector.v;
		yVector.a -= .1*yVector.v;
		RotVector.a -= .1*RotVector.v;
		
		integrator.integrate(xVector, t, dt, xVector.a/mass);
		integrator.integrate(yVector, t, dt, yVector.a/mass);
		integrator.integrate(RotVector, t, dt, RotVector.a/mass);
		xVector.a = 0;
		yVector.a = 0;
		RotVector.a = 0;
	}
}
